var req = require('../../interfaceImpl.js');
var config = require('../../interfaceConfig.js');
var app = getApp();
var pageIndex = 1;
const pageSize = 10;
var detail = ''
Page({
    data: {
        bill: []
    },
    onLoad: function (options) {
        this.setData({
            head: app.globalData.userinfo.avatarUrl,
            name: app.globalData.userinfo.nickName,
            money: app.globalData.loginuserinfo.balance,
            cardNum: app.globalData.loginuserinfo.cardNum,
            vipType: app.globalData.loginuserinfo.vipType
        })
        //TODO我的账单
        this.GetBillList();
    },
    detail: function (e) {
        wx.navigateTo({
            url: '../member/detailBill?id=' + e.currentTarget.dataset.id + '&types=' + e.currentTarget.dataset.types
        })
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.GetBillList();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        pageIndex++;
        return req.BillsList(pageIndex, pageSize, app.globalData.token).then(res => {
            //console.log( this.data.bill)
            this.data.bill = this.data.bill.concat(res.data.data)
            this.setData({ bill: this.data.bill })
        })
    },
    GetBillList:function(){
        return req.BillsList(pageIndex, pageSize, app.globalData.token).then(res => {
            if (res.data.success) {
                this.setData({ bill: res.data.data });
            }
            else {
                wx.showModal({
                    title: '获取失败',
                    content: res.data.data,
                    showCancel: false,
                    success: function (res) {
                    }
                })
            }
        })
    }
})